import 'package:flutter/material.dart';
import '../layout/CardPage.dart';
import '../layout/ContainerPage.dart';
import '../layout/GridViewPage.dart';
import '../layout/ListViewPage.dart';
import '../layout/StackPage.dart';

class SubTabPage extends StatefulWidget {
  @override
  _SubTabPageState createState() => _SubTabPageState();
}

class _SubTabPageState extends State<SubTabPage> with SingleTickerProviderStateMixin {
  var _tabController;
  @override
  void initState() {
    super.initState();
    _tabController = new TabController(
      vsync: this, //动画效果的异步处理，默认格式，背下来即可
      length: 5 //需要控制的Tab页数量
    );
  }

  //当整个页面dispose时，记得把控制器也dispose掉，释放内存
  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: new Text('车贷列表'),
        centerTitle: true,
      ),
      body: new TabBarView(
        controller: _tabController,
        children: <Widget>[
          new CardPage(),
          new ContainerPage(),
          new GridViewPage(),
          new ListViewPage(),
          new StackPage(),
        ],
      ),
      bottomNavigationBar: new Material(
        color: Colors.blue,
        child: new TabBar(
          controller: _tabController,
          tabs: <Widget>[
            new Tab(text: "Card", icon: new Icon(Icons.home)),
            new Tab(text: "Container", icon: new Icon(Icons.map)),
            new Tab(text: "GridView", icon: new Icon(Icons.message)),
            new Tab(text: "ListView", icon: new Icon(Icons.menu)),
            new Tab(text: "Stack", icon: new Icon(Icons.grade)),
          ],
        ),
      ),
    );
  }
}
